package com.yanggu.scala.chapater11.exercise

import scala.collection.mutable.ArrayBuffer

object Exercise02 {

  def main(args: Array[String]): Unit = {
    //val sentence = "AAAAAAAAAABBBBBBBBCCCCCDDDDDDD"
    //将sentence 中各个字符，通过foldLeft存放到 一个ArrayBuffer中
    //目的：理解foldLeft的用法.
    val sentence = "AAAAAAAAAABBBBBBBBCCCCCDDDDDDD"
    val array = ArrayBuffer[Char]()

    def putArray(arr: ArrayBuffer[Char], c: Char) = {
      arr.append(c)
      arr
    }

    println(sentence.foldLeft(array)(putArray))
  }

}
